;LED0 EQU 0x422101a0 
LED0 EQU 0x422201b4
;;;;;;;0x42000000+(A-0x40000000)*32+n*4
;;;;;;;for PC13 A is 0x4201100c, n is 13
;;;;;;;0x42000000 + 0x1100c*32+13*4 = 0x422201b4

RCC_APB2ENR EQU (0x40021000 + 0x18)
GPIOC_CRH EQU (0x40011000 + 4)
Stack_Size      EQU     0x400
  AREA    STACK, NOINIT, READWRITE, ALIGN=3
Stack_Mem       SPACE   Stack_Size
__initial_sp
  AREA    RESET, DATA, READONLY
__Vectors       
  DCD     __initial_sp               ; Top of Stack
  DCD     Reset_Handler              ; Reset Handler
      
  AREA    |.text|, CODE, READONLY
  THUMB
  REQUIRE8
  PRESERVE8
  IMPORT	__main
;  EXPORT	Delay
  EXPORT	LED_Init
  EXPORT	LED_ON
  EXPORT	LED_OFF
  ENTRY
Reset_Handler 
  B __main
  BL LED_Init
  
MainLoop        
  BL LED_ON
;  BL Delay
  BL LED_OFF
;  BL Delay
  B MainLoop

LED_Init
  PUSH {R0,R1, LR}
;;;;;;;;;  setup enable Port C power start
  LDR R0,=RCC_APB2ENR
  LDR R0,[R0]
  ORR R0,R0,#0x10 ;;enable PC power
  LDR R1,=RCC_APB2ENR
  STR R0,[R1];;write register to enable
;;;;;;;;;setup enable Port C pwer end  


;;;;;;;;setup GPIO mode start
  LDR R0,=GPIOC_CRH
  LDR R0,[R0]
  BIC R0,R0,#0x00F00000 ;;enable pc13 as output mask
  LDR R1,=GPIOC_CRH
  STR R0,[R1]
  LDR R0,=GPIOC_CRH
  ORR R0,R0,#0x00300000;; enable pc13 as output
  LDR R1,=GPIOC_CRH
  STR R0,[R1]
;;;;;;;;setup GPIO mode end  

  MOV R0,#1 ;;led off
  LDR R1,=LED0
  STR R0,[R1]
  
  POP {R0,R1,PC} ;; return 
  
LED_ON
  PUSH {R0,R1, LR}    
  MOV R0,#0 
  LDR R1,=LED0
  STR R0,[R1]
  POP {R0,R1,PC} ;; return
  
LED_OFF
  PUSH {R0,R1, LR}    
  MOV R0,#1 
  LDR R1,=LED0
  STR R0,[R1]
  POP {R0,R1,PC}   ;; return          
  
    ;         NOP
             END
 